import { Component, OnInit,Input,Output,EventEmitter } from '@angular/core';
import {TranslateService} from '@ngx-translate/core';
import {TreeService} from '../../../services/tree.service'


@Component({
    selector: 'app-modal-dialog',
    templateUrl: './modal-dialog.component.html',
    styleUrls: ['./modal-dialog.component.css']
})

export class ModalDialogComponent implements OnInit{

    // dialogShow:boolean=false;
    
    data={
        group:'',
        filters:[]
    }
    editdata:any;
    editdialogshow:boolean=false;
    param:string;
    // columnObjs=[]

    constructor(
        private treeservice:TreeService,
        public translate:TranslateService,
    ){
        translate.addLangs(['zh','en']);                          //添加语言支持
        translate.setDefaultLang('en');                           //设置默认语言
        let broswerLang = translate.getBrowserLang();              //获取浏览器支持的语言
        console.log(broswerLang)                                   //zh
        translate.use(broswerLang.match(/zh|en/) ? broswerLang : 'en');
    }


    @Input() dialogShow:boolean=false;
    @Input() columnObjs:any=[]
    @Input() initItem:any;
    @Input() editevent:any;
    @Output() dialogfalse=new EventEmitter<any>()
    @Output() alias=new EventEmitter<any>()
    @Output() aliasevent=new EventEmitter<any>()
    ngOnInit(){
        
    }

    ngDoCheck(){
        console.log(this.initItem)
        this.editdata=this.initItem
    }
    close(){
        this.dialogShow=false
        this.dialogfalse.emit(this.dialogShow)
    }

    addColumn(column){
        this.data.filters.push(column)
        console.log(this.data.filters)
    }

    editFilter(column){
        alert(column)
        this.editdialogshow=true;
        this.param=column
    }

    resive(data){
        this.editdialogshow=data
    }
    ok(ev){
        this.dialogShow=false
        this.dialogfalse.emit(this.dialogShow)
        console.log(this.data.group)
        this.alias.emit(this.data.group)
        this.aliasevent.emit(ev)
        this.data.group=''
    }
}